﻿using Application.AppService.JurisdictionAppService;
using Application.AppService.UserAppService;
using Application.AppService.UserRolesAppService;
using AutoMapper;
using Domain;
using Domain.Entity;
using Domain.Repository;
using Microsoft.AspNetCore.Mvc;

namespace UI.Controllers.authority_management_权限管理_
{
	public class UserController : Controller
	{
		private readonly IUsersAppService usersAppService;
		
		private readonly IMapper mapper;
		private readonly IUserRolesAppService userRolesAppService;
		

		public UserController(IUsersAppService usersAppService , IMapper mapper,IUserRolesAppService userRolesAppService )
		{
			this.usersAppService = usersAppService;
			this.mapper = mapper;
			this.userRolesAppService = userRolesAppService;

			
		}
		public IActionResult Index()
		{
			return View();
		}
		public IActionResult Index1()
		{
			return View();
		}
		public IActionResult Index2()
		{
			return View();
		}

		public IActionResult Index3()
		{
			return View();
		}
		public async Task<IActionResult> GetUsersWithRoles()
		{
			var userRoles = await userRolesAppService.GetUsersWithRolesAsync();
			return Json(userRoles);
		}
		[HttpPost("UserRolesFenYe")]
		public IActionResult UserRolesFenYe(int page, int pageSize)
		{
			UserRolesFenYe userRolesFenYe = userRolesAppService.UserRolesFenYe(page, pageSize);
			return Json(userRolesFenYe);
		}
		[HttpGet("MaxUid")]
		public async Task<IActionResult> MaxUid()
		{
			int i = await usersAppService.maxUId();
			return Json(i);
		}
		[HttpPost("UserRolesAdd")]
		public async Task<IActionResult> UserRolesAdd(UserRoles userRoles)
		{
			bool i = await userRolesAppService.UserRolesAdd(userRoles);
			return Json(i);
		}
		[HttpPost("SelectUserRolesById")]
		public async Task<IActionResult> SelectUserRolesById(int id)
		{
			UserRoles userRoles = await userRolesAppService.SelectUserRolesById(id);
			return Json(userRoles);
		}
		[HttpPost("UserRolesUpdate")]
		public async Task<IActionResult> UserRolesUpdate(UserRoles userRoles)
		{
			bool i = await userRolesAppService.UserRolesUpdate(userRoles);
			return Json(i);
		}
		[HttpPost("UserRolesDelete")]
		public async Task<IActionResult> UserRolesDelete(int id)
		{
			bool i = await userRolesAppService.UserRolesDelete(id);
			return Json(i);
		}
		public  IActionResult DataUser(int page, int pageSize)
		{
			UserFenYe userFenYe = usersAppService.DataUser(page, pageSize);
			return Json(userFenYe);
		}
		public async Task<IActionResult> AddUser(User user)
		{
			bool i =  await usersAppService.AddUser(user);
			return Json(i);
		}
		public async Task<IActionResult> UpDateUser(User user)
		{
			bool i = await usersAppService.UpDateUser(user);
			return Json(i);
		}
		public async Task<IActionResult> DelectUser(int uid)
		{
			bool i = await usersAppService.DeleteUser(uid);
			return Json(i);
		}
		

    }
}
